/**
 * 
 */
package controller;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.logging.SimpleFormatter;
import exception.ApplicationException;
import service.SeniorAdminQueryHelper;
import service.SeniorAdminService;
import service.SeniorAdminServiceImpl;
import utils.MD5_Test;
import utils.Page;

import model.User;

/**
 * @ClassName: SeniorAdminAction
 * @Description:
 * @author Hongming Wu
 * @date 2013-12-6
 * 
 */
public class SeniorAdminAction {
	private User user;
	private List<User> userList;
	private SeniorAdminQueryHelper helper = null;
	private Page page = null;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;

	}

	public SeniorAdminQueryHelper getHelper() {
		return helper;
	}

	public void setHelper(SeniorAdminQueryHelper helper) {
		this.helper = helper;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public String home() {
		return "homePage";
	}

	public String input() {

		return "inputPage";
	}

	public String create() {

		SeniorAdminService sas = new SeniorAdminServiceImpl();
		user.setUser_Pwd(MD5_Test.MD5("12345"));
		user.setStatus(1);

		sas.createUser(user);

		System.out.println("create successful!");
		return "success";
	}

	public String loadAllUser() {

		if (page == null) {
			page = new Page();

		}
		SeniorAdminService sas = new SeniorAdminServiceImpl();
		page = sas.loadPagedUsers(page, helper);

		return "loadPagedUserPage";
	}

	public String forUpdateUser() {
		SeniorAdminService sas = new SeniorAdminServiceImpl();
		user = sas.getUserByID(user.getUser_ID());

		return "updatePage";
	}

	public String update() {
		SeniorAdminService sas = new SeniorAdminServiceImpl();
		try {
			sas.updateUser(user);
		} catch (ApplicationException e) {
			e.printStackTrace();
		}
		System.out.println("update successful!");
		return "success";
	}

	public String remove() {
		SeniorAdminService sas = new SeniorAdminServiceImpl();
		sas.removeUser(user.getUser_ID());
		System.out.println("remove successful!");
		return "success";

	}
}
